﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Kassasysteem_TacoTruijens
{
    public partial class show : System.Web.UI.Page
    {
        private DataClassesDataContext Database = new DataClassesDataContext();
        private Voorstelling selectedShow;

        protected void Page_Load(object sender, EventArgs e)
        {
            initSelectedShow();
            initTableTickets();
        }

        private void initSelectedShow()
        {
            DateTime datetime = DateTime.Parse(Request.QueryString["datetime"]);
            int roomNumber = Convert.ToInt32(Request.QueryString["roomnumber"]);
            String movieName = Request.QueryString["moviename"];

            var shows = from s in Database.Voorstellings
                        where s.datumtijd.Equals(datetime) && s.Zaal.nummer == roomNumber && s.Film.naam.Replace((char)39, ' ').Equals(movieName)
                        select s;

            selectedShow = shows.First();   
        }

        private void initTableTickets()
        {
            TableRow tableRowAdult = new TableRow();
            TableRow tableRowChild = new TableRow();
            TableRow tableRow50plus = new TableRow();
            TableRow tableRowCJPStudent = new TableRow();
            TableRow tableRowFree = new TableRow();
            TableRow tableRow3DGlasses = new TableRow();
            TableRow tableRowPreviousNext = new TableRow();

            TableCell tableCellAdultDescription = new TableCell();
            TableCell tableCellChildDescription = new TableCell();
            TableCell tableCell50plusDescription = new TableCell();
            TableCell tableCellCJPStudentDescription = new TableCell();
            TableCell tableCellFreeDescription = new TableCell();
            TableCell tableCell3DGlassesDescription = new TableCell();
            TableCell tableCellPrevious = new TableCell();

            TableCell tableCellAdultAmount = new TableCell();
            TableCell tableCellChildAmount = new TableCell();
            TableCell tableCell50plusAmount = new TableCell();
            TableCell tableCellCJPStudentAmount = new TableCell();
            TableCell tableCellFreeAmount = new TableCell();
            TableCell tableCell3DGlassesAmount = new TableCell();
            TableCell tableCellNext = new TableCell();

            tableCellAdultAmount.CssClass = "alignRight";
            tableCellChildAmount.CssClass = "alignRight";
            tableCell50plusAmount.CssClass = "alignRight";
            tableCellCJPStudentAmount.CssClass = "alignRight";
            tableCellFreeAmount.CssClass = "alignRight";
            tableCell3DGlassesAmount.CssClass = "alignRight";
            tableCellNext.CssClass = "alignRight";

            tableCellAdultDescription.Text = "Volwassene:";
            tableCellChildDescription.Text = "Kind:";
            tableCell50plusDescription.Text = "50 plus:";
            tableCellCJPStudentDescription.Text = "CJP/Student:";
            tableCellFreeDescription.Text = "Gratis:";
            tableCell3DGlassesDescription.Text = "3D bril:";
            tableCellPrevious.Text = "<br /><input type='button' value='Terug' onclick='previous()' />";

            tableCellAdultAmount.Text = "<input type='button' value='-' onclick='substractAdultCounter()' /><input type='text' name='inputTextAdult' id='inputTextAdult' value='0' readonly='readonly' class='counter' /><input type='button' value='+' onclick='addAdultCounter()' />";
            tableCellChildAmount.Text = "<input type='button' value='-' onclick='substractChildCounter()' /><input type='text' name='inputTextChild' id='inputTextChild' value='0' readonly='readonly' class='counter' /><input type='button' value='+' onclick='addChildCounter()' />";
            tableCell50plusAmount.Text = "<input type='button' value='-' onclick='substractFiftyplusCounter()' /><input type='text' name='inputText50plus' id='inputText50plus' value='0' readonly='readonly' class='counter' /><input type='button' value='+' onclick='addFiftyplusCounter()' />";
            tableCellCJPStudentAmount.Text = "<input type='button' value='-' onclick='substractCJPStudentCounter()' /><input type='text' name='inputTextCJPStudent' id='inputTextCJPStudent' value='0' readonly='readonly' class='counter' /><input type='button' value='+' onclick='addCJPStudentCounter()' />";
            tableCellFreeAmount.Text = "<input type='button' value='-' onclick='substractFreeCounter()' /><input type='text' name='inputTextFree' id='inputTextFree' value='0' readonly='readonly' class='counter' /><input type='button' value='+' onclick='addFreeCounter()' />";
            tableCell3DGlassesAmount.Text = "<input type='button' value='-' onclick='substract3DGlassesCounter()' /><input type='text' name='inputText3DGlasses' id='inputText3DGlasses' value='0' readonly='readonly' class='counter' /><input type='button' value='+' onclick='add3DGlassesCounter()' />";
            tableCellNext.Text = "<br /><input type='button' value='Volgende' onclick='next()' />";

            tableRowAdult.Cells.Add(tableCellAdultDescription);
            tableRowChild.Cells.Add(tableCellChildDescription);
            tableRow50plus.Cells.Add(tableCell50plusDescription);
            tableRowCJPStudent.Cells.Add(tableCellCJPStudentDescription);
            tableRowFree.Cells.Add(tableCellFreeDescription);
            tableRow3DGlasses.Cells.Add(tableCell3DGlassesDescription);
            tableRowPreviousNext.Cells.Add(tableCellPrevious);

            tableRowAdult.Cells.Add(tableCellAdultAmount);
            tableRowChild.Cells.Add(tableCellChildAmount);
            tableRow50plus.Cells.Add(tableCell50plusAmount);
            tableRowCJPStudent.Cells.Add(tableCellCJPStudentAmount);
            tableRowFree.Cells.Add(tableCellFreeAmount);
            tableRow3DGlasses.Cells.Add(tableCell3DGlassesAmount);
            tableRowPreviousNext.Cells.Add(tableCellNext);

            tableTickets.Rows.Add(tableRowAdult);
            tableTickets.Rows.Add(tableRowChild);
            tableTickets.Rows.Add(tableRow50plus);
            tableTickets.Rows.Add(tableRowCJPStudent);
            tableTickets.Rows.Add(tableRowFree);
            
            if (selectedShow.Film._3d)
            {
                tableTickets.Rows.Add(tableRow3DGlasses);
            }

            tableTickets.Rows.Add(tableRowPreviousNext);
        }
    }
}